package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.StringTokenizer;

@RestController("adminShopController")
@Slf4j
@Api("店铺管理状态接口")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;


    private static final String SHOP_STATUS = "shop_status";

    /**
     * 设置店铺的状态
     * @param status
     * @return
     */
    @PutMapping("/admin/shop/{status}")
    public Result<String> setStatus(@PathVariable Integer status){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    public Result<Integer> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(SHOP_STATUS);
        return Result.success(status);
    }

}
